﻿using StoryTeller.Infrastructure.DataAccess.Parser;
using StoryTeller.Infrastructure.DataAccess.DAL.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StoryTeller.Domain;

namespace StoryTeller.Infrastructure.DataAccess.DAL
{
    public class StoryRatingDAL : BaseDAL, IStoryRatingDAL
    {
        public void Insert(Domain.StoryRating entidade)
        {
            Entities.StoryRating.Add(entidade.ParseDomainToEntity());

            Save();
        }

        public void Delete(int userId, int storyId)
        {
            EStoryRating cat = Entities.StoryRating.First(c => c.IdStory == storyId && c.IdUser == userId);

            if (cat != null)
            {
                Entities.StoryRating.Remove(cat);

                Save();
            }
        }

        public ICollection<Domain.StoryRating> Select(int storyId)
        {
            ICollection<EStoryRating> coll = Entities.StoryRating.Where(s => s.IdStory == storyId).ToList();

            return coll.Select(c => c.ParseEntityToDomain()).ToList();
        }
    }
}
